using System;
using System.Collections.Generic;
using System.Text;
using OpenComposite.Base.Designer;
using System.Drawing;

namespace OpenComposite.EII.Designer.BRules
{
	public class ActionSymbol : Symbol, IConnector, IConnectorFactory
	{
		#region Initialization
		public ActionSymbol()
		{
			init();
		}
		private void init()
		{
			this.BeginUpdate();

			this.Text = "Action";
			this.Size = new Size(80, 50);
			this.MinimumSize = new Size(80, 50);

			this.NameTextBox.Visible = false;

			//
			// _txtResult
			//
			txtResult = new TextBox();
			txtResult.AutoSize = false;
			txtResult.BorderVisibilityStyle = BorderVisibilityStyle.Always;
			txtResult.Bounds = new Rectangle(0, 20, 99, 29);
			txtResult.Anchor = System.Windows.Forms.AnchorStyles.Bottom |
				System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right |
				System.Windows.Forms.AnchorStyles.Top;
			txtResult.Text = "";

			this.Controls.Add(txtResult);

			this.EndUpdate();
		}
		#endregion

		#region Public Members

		#region Methods
		public void SetIdentifier(Guid id)
		{
			guidIdentifier = id;
		}
		#endregion

		#region Properties
		public virtual string ResultString
		{
			get { return txtResult.Text; }
			set { txtResult.Text = value; }
		}
		public TextBox TextBox
		{
			get { return txtResult; }
		}
		#endregion

		#region Override
		public override bool CanFocused
		{
			get
			{
				return true;
			}
		}
		public override bool CanMove
		{
			get
			{
				return false;
			}
		}
		public override bool CanResize
		{
			get
			{
				return false;
			}
		}
		public override bool CanSelect
		{
			get
			{
				return false;
			}
		}
		public override bool IsContainer
		{
			get
			{
				return false;
			}
		}
		public override bool NoClip
		{
			get
			{
				return false;
			}
		}
		public override bool UseGrid
		{
			get
			{
				return false;
			}
		}

		public override object GetDragObject(Point location, System.Windows.Forms.MouseButtons button)
		{
			return this;
		}

		public override void PaintBackground(System.Windows.Forms.PaintEventArgs pe)
		{
			base.PaintBackground(pe);

			Rectangle bounds = this.GetPaintBounds();
			Rectangle rectTitle = new Rectangle(bounds.Location, new Size(bounds.Width, 20));
			pe.Graphics.DrawString(this.Text, this.Font, this.ForeBrush, rectTitle);
		}
		public override void Paint(System.Windows.Forms.PaintEventArgs pe)
		{
			base.Paint(pe);
		}
		#endregion

		#endregion

		#region Protected Members

		#region Variables
		protected TextBox txtResult;
		#endregion

		#region Override
		protected override void OnVisibleChanged()
		{
			// do nothing
		}
		protected override void OnRemoved(EventArgs e)
		{
			base.OnRemoved(e);
		}
		protected override Rectangle CalculateClientArea()
		{
			return this.Bounds;
		}
		#endregion

		#endregion

		#region Private Members

		#region Variables
		//private TextBox _txtResult;
		#endregion

		#endregion

		#region IConnector Members

		public Point GetRouteStart(RouteDockDirection dock)
		{
			Rectangle bounds = this.GetPaintBounds();
			return new Point(bounds.Right, bounds.Top + (int)( bounds.Height / 2 ));
		}

		public Point GetRouteEnd(RouteDockDirection dock)
		{
			return Point.Empty;
		}

		#endregion

		#region IConnectorFactory Members

		public override bool CreateRouteStart(DesignerControl controlEnd,
			out IConnector connector, out System.Drawing.Drawing2D.LineCap cap,
			out System.Drawing.Drawing2D.CustomLineCap customcap, out RouteDockDirection dockStart,
			out RouteDockDirection dockEnd, out bool useStartConnectorAsRouteStart)
		{
			bool bOK = base.CreateRouteStart(controlEnd,
				out connector, out cap, out customcap, out dockStart, out dockEnd, out useStartConnectorAsRouteStart);

			dockStart = RouteDockDirection.Right;
			return bOK;
		}

		public override bool CreateRouteEnd(DesignerControl controlStart,
			out IConnector connector, out System.Drawing.Drawing2D.LineCap cap,
			out System.Drawing.Drawing2D.CustomLineCap customcap, out RouteDockDirection dockStart,
			out RouteDockDirection dockEnd, out bool useEndConnectorAsRouteEnd)
		{
			connector = null;
			cap = System.Drawing.Drawing2D.LineCap.Custom;
			customcap = new System.Drawing.Drawing2D.AdjustableArrowCap(5.0f, 5.0f, true);
			dockStart = RouteDockDirection.Right;
			dockEnd = RouteDockDirection.Left;
			useEndConnectorAsRouteEnd = false;

			return true;
		}

		#endregion
	}
}
